%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
clear all; close all; clc;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Modify main_str to match path on your machine
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
main_str = 'C:\Users\Marco\Dropbox\Housing_Brainstorming\Information_disclosure';
% main_str = 'L:\agargano\Dropbox\Housing_Brainstorming\Information_disclosure';

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load_str = [main_str,'\Replication_code_RFS\Model\Output\Last'];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FontSize=18;
MarkSize=9;
XlabelSize = 16;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Load

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sel_j_vec    = 1; % generates Figure 2 (standard cost function for determining valuations)
% sel_j_vec    = 2; % generates Figure D.3 (cost of determining valuations is AUD 8,000)
n_j          = size(sel_j_vec,2);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load([load_str,'\Results_out_1_Nash_Loop.mat']);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
q_vec        = start_bid_scale-1; % vector of values of alpha

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Figure (specific value)

for n = 1:n_j

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    sel_j         = sel_j_vec(n); % select model solution

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    eq_Erev_vec  = eq_Erev_mat(:,sel_j);   
    eq_EbidW_vec     = eq_EbidW_mat(:,sel_j);
    eq_Esales_vec    = eq_Esales_mat(:,sel_j);
    eq_Psales_vec    = eq_Psales_mat(:,sel_j);
    eq_Nall_vec      = eq_Nall_mat(:,sel_j);
    eq_EbidN_vec     = eq_EbidN_mat(:,sel_j);
    eq_p_hcost0_vec  = eq_p_hcost0_mat(:,sel_j);

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    figure(n);
    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    %%%%%%%%%%%%%%%
    subplot(3,2,1);
    %%%%%%%%%%%%%%%
    temp_max=NaN(length(eq_Erev_vec),1); temp_max(eq_Erev_vec==max(eq_Erev_vec))=max(eq_Erev_vec);
    temp_eq_Erev_vec=eq_Erev_vec; temp_eq_Erev_vec(eq_Erev_vec==max(eq_Erev_vec))=NaN;
    plot(q_vec,temp_eq_Erev_vec/1000,'Linestyle','none','marker','d','MarkerSize',MarkSize,'MarkerFaceColor','blue'); hold on;
    plot(q_vec,temp_max/1000,'*','MarkerSize',MarkSize,'MarkerFaceColor','red'); grid on; 
    xticks([-0.2:0.05:0.2]); xlim([-0.20,0.20]); grid on;
    title('E[Seller Revenue]')
    ylabel('AUD 1,000'); set(gca,'fontsize',FontSize); 
    xlabel('$\alpha$','interpreter','latex','fontsize',XlabelSize); 
    %%%%%%%%%%%%%%%
    subplot(3,2,2);
    %%%%%%%%%%%%%%%
    temp=eq_EbidW_vec;
    plot(q_vec,temp/1000,'Linestyle','none','marker','d','MarkerSize',MarkSize,'MarkerFaceColor','blue'); hold on;    
    xticks([-0.2:0.05:0.2]); xlim([-0.20,0.20]); grid on;
    ylabel('AUD 1,000');
    title('E[Bidder Surplus]')
    set(gca,'fontsize',FontSize); 
    xlabel('$\alpha$','interpreter','latex','fontsize',XlabelSize); 
    %%%%%%%%%%%%%%%    
    subplot(3,2,3);
    %%%%%%%%%%%%%%%
    plot(q_vec,(eq_Esales_vec/1000)+650,'Linestyle','none','marker','d','MarkerSize',MarkSize,'MarkerFaceColor','blue'); hold on;
    xticks([-0.2:0.05:0.2]); xlim([-0.20,0.20]); grid on;
    ylabel('AUD 1,000');
    title('E[Sale Price|Sale]')
    set(gca,'fontsize',FontSize); 
    xlabel('$\alpha$','interpreter','latex','fontsize',XlabelSize); 
    %%%%%%%%%%%%%%% 
    subplot(3,2,4);
    %%%%%%%%%%%%%%%
    plot(q_vec,100*eq_Psales_vec,'Linestyle','none','marker','d','MarkerSize',MarkSize,'MarkerFaceColor','blue'); hold on;
    xticks([-0.2:0.05:0.2]); xlim([-0.20,0.20]); grid on;
    ylabel('(%)');
    title('P(Sale)');
    set(gca,'fontsize',FontSize); 
    xlabel('$\alpha$','interpreter','latex','fontsize',XlabelSize); 
    %%%%%%%%%%%%%%%
    subplot(3,2,5);
    %%%%%%%%%%%%%%%
    plot(q_vec,eq_Nall_vec.*eq_EbidN_vec,'Linestyle','none','marker','d','MarkerSize',MarkSize,'MarkerFaceColor','blue'); hold on;
    xticks([-0.2:0.05:0.2]); xlim([-0.20,0.20]); grid on;
    title('E[Number of Bidders]');
    set(gca,'fontsize',FontSize); 
    xlabel('$\alpha$','interpreter','latex','fontsize',XlabelSize); 
    %%%%%%%%%%%%%%%
    subplot(3,2,6);
    %%%%%%%%%%%%%%%
    plot(q_vec,100*eq_EbidN_vec,'Linestyle','none','marker','d','MarkerSize',MarkSize,'MarkerFaceColor','blue'); hold on;
    xticks([-0.2:0.05:0.2]); xlim([-0.20,0.20]); grid on;
    ylabel('(%)');
    title('E[Fraction of Bidders]');
    set(gca,'fontsize',FontSize); 
    xlabel('$\alpha$','interpreter','latex','fontsize',XlabelSize); 

end
